<?php
/*
Copyright 2008, Nathalia


Author:
Nathalia Sautchuk Patrício          (nathalia.sautchuk@gmail.com)

*/
class Editar extends TPage
{
	public function onInit($param)
	{
		parent::onInit($param);
		if(!$this->IsPostBack)  // if the page is initially requested
		{
            $avaliacaoRecord           = $this->AvaliacaoRecord;
            $this->Nota->Text          = $avaliacaoRecord->Nota;          
            $this->Comentario->Text    = $avaliacaoRecord->Comentario;          
            //$this->AvaliadorID->Text = $avaliacaoRecord->AvaliadorID;        
            //$this->ArtigoID->Text    = $avaliacaoRecord->ArtigoID;        
		}
	}

	public function editarAvaliacao($sender,$param)
	{
		if($this->IsValid)  // when all validations succeed
		{
            $avaliacaoRecord                = $this->AvaliacaoRecord;
            $avaliacaoRecord->Nota          = $this->Nota->Text; 
            $avaliacaoRecord->Comentario    = $this->Comentario->Text; 
            $avaliacaoRecord->Status        = 1;   
            $avaliacaoRecord->DataAvaliacao = date('Y-m-d');  

			// saves to the database via Active Record mechanism
			$avaliacaoRecord->save();

			// redirects the browser to the homepage
			$this->Response->redirect("./index.php?page=Avaliacao.Listar");
		}
	}

	protected function getAvaliacaoRecord ()
	{
		// if the 'username' GET var is not empty and the current user
		// is an administrator, we use the GET var value instead.
		if($this->Request['avaliacaoID'] !== null)
			$avaliacaoID = $this->Request['avaliacaoID'];

		// use Active Record to look for the specified username
		$avaliacaoRecord= AvaliacaoRecord::finder()->findByAvaliacaoID($avaliacaoID);
		if(!($avaliacaoRecord instanceof AvaliacaoRecord))
			throw new THttpException(500,'AvaliacaoID is invalid.');
		return $avaliacaoRecord;
	}


}
?>
